const { mongoose, db } = require('../utils/mongoose')

let schema = mongoose.Schema({
    sId: { type: String, required: false },
    class: { type: String, required: false },
    age: { type: String, required: false },
    city: { type: String, required: false },
    degree: { type: String, required: false },
    productUrl: { type: String, required: false },
    description: { type: String, required: false },
    avatar: { type: String, required: false },
    token: { type: String, required: true }
})

let Collection = mongoose.model('students', schema)
//增
const save = (data) => {
    let model = new Collection(data)
    return model.save()
        .then(res => res)
        .catch(err => {
            console.log(err);
            return false;
        })
}
// 删
let del = (query = {}) => {
    return Collection.deleteOne(query)
        .then(res=>res)
        .catch(err=>{
            console.log(err)
            return false;
        })
}

// 改
let update = (query, updated) => {
    return Collection.updateOne(query, updated)
        .then(res=>res)
        .catch(err=>{
            console.log(err);
            return false;
        })

}
// 查
let find = (query = {}) => {
    return Collection.find(query)
        .then(res=>res)
        .catch(err=>{
            console.log(err)
            return false;
        })
}
module.exports = {
    save,
    find,
    del,
    update
}